library("lattice")
library("parallel")
library("corrplot")
library("plyr")
z.prop = function(x1,x2,n1,n2){
  numerator = (x1/n1) - (x2/n2)
  p.common = (x1+x2) / (n1+n2)
  denominator = sqrt(p.common * (1-p.common) * (1/n1 + 1/n2))
  z.prop.ris = numerator / denominator
  return(z.prop.ris)
}
cor.clavage.gen <- function(df, Type.segment, threshold, left.b = 0, right.b = 1) {
  df_length = length(df)
  v.df <- lapply(df, function(x) { droplevels(subset(x, x$Type == Type.segment)) })
  v.df_true <- lapply(v.df, function(x) droplevels(subset(x, x$Clavage)))
  
  #t_full <- lapply(v.df, function(x) { table(x$subject_id)})
  t_full <- lapply(v.df, function(x) { unlist(by(x, x$subject_id, function(y) sum(y$abundance), simplify=FALSE)) })
  #t_full <- t_full[-(length(t_full) - 2)]
  #t_true <- lapply(v.df_true, function(x) table(x$subject_id))
  t_true <- lapply(v.df_true, function(x) { unlist(by(x, x$subject_id, function(y) sum(y$abundance), simplify=FALSE)) })
  #t_true <- t_true[-(length(t_true) - 2)]
  
  #ind <- lapply(t_true, function(x) which(x > threshold))
  #t_full <- mapply(function(x, i) { x[i] }, t_full, ind, SIMPLIFY = FALSE)
  t_true <- lapply(t_true, function(x) { x[x > threshold] })
  t_full <- mapply(function(x, y) { x[names(y)] }, t_full, t_true, SIMPLIFY = FALSE)
  #mapply(function(x, y) { sort(x / y) }, t_true, t_full)
    
  intersectSeveral <- function(...) { Reduce(function(x, y) { intersect(x, y) }, list(...)[[1]]) }
  t_full_intersected <- lapply(t_full, function(x) x[intersectSeveral(lapply(t_true, names))])
  t_true_intersected <- lapply(t_true, function(x) x[intersectSeveral(lapply(t_true, names))])
  #print(t_full_intersected)
  #mapply(function(x, y) sort(x / y), t_true_intersected, t_full_intersected, SIMPLIFY = FALSE)
  
  p_clavage <- mapply(function(x, y) x / y, t_true_intersected, t_full_intersected, SIMPLIFY = FALSE)
  #apply(simplify2array(p_clavage), 1, mean)
  #apply(simplify2array(p_clavage), 1, sd)
  
  s2a_p_clavage <- simplify2array(p_clavage)
  s2a_p_clavage
}

df.processing <- function(df, threshold.perc.identity = 100) {
  df <- mclapply(df, function(x) {x$Clavage <- toupper(x$Clavage); x }, mc.cores = detectCores())
  df <- mclapply(df, function(x) {x$Clavage <- as.logical(x$Clavage); x}, mc.cores = detectCores())
  df <- mclapply(df, function(x) {x$subject_id <- as.factor(x$subject_id); x}, mc.cores = detectCores())
  df <- mclapply(df, function(x) {x$Type <- as.factor(x$Type); x}, mc.cores = detectCores())
  df <- mclapply(df, function(x) subset(x, perc_identity >= threshold.perc.identity), mc.cores = detectCores())
  df
}

cor.clavage.gen.all <- function(df, threshold = 1000) {
  list("V"       = cor.clavage.gen(df, "V", threshold = threshold),
       "D left"  = cor.clavage.gen(df, "D left", left.b = 0.5, threshold = threshold),
       "D right" = cor.clavage.gen(df, "D right", left.b = 0.5, threshold = threshold),
       "J"       = cor.clavage.gen(df, "J", left.b = 0.8, threshold = threshold)
  )
}

pairs.plots <- function(barcodes) {
  print(pairs(barcodes[["V"]], xlim = c(0, 1), ylim = c(0, 1), main = "V"))
  print(pairs(barcodes[["D left"]], xlim = c(0.5, 1), ylim = c(0.5, 1), main = "D left"))
  print(pairs(barcodes[["D right"]], xlim = c(0.5, 1), ylim = c(0.5, 1), main = "D right"))
  print(pairs(barcodes[["J"]], xlim = c(0.8, 1), ylim = c(0.8, 1), main = "J"))
}

permutation.test <- function(a, b, df.length) {
  tmp <- matrix( c(a, sample(b)), nrow = length(a), ncol = df.length )
  #print(tmp)
  cor(tmp[,1], tmp[,2])
}

z.test <- function(df, Type.segment, threshold, left.b = 0, right.b = 1) {
  df_length = length(df)
  stopifnot(length(df) == 2)
  v.df <- lapply(df, function(x) { droplevels(subset(x, x$Type == Type.segment)) })
  v.df_true <- lapply(v.df, function(x) droplevels(subset(x, x$Clavage)))
  
  t_full <- lapply(v.df, function(x) { unlist(by(x, x$subject_id, function(y) sum(y$abundance), simplify=FALSE)) })
  t_true <- lapply(v.df_true, function(x) { unlist(by(x, x$subject_id, function(y) sum(y$abundance), simplify=FALSE)) })
  t_true <- lapply(t_true, function(x) { x[x > threshold] })
  t_full <- mapply(function(x, y) { x[names(y)] }, t_full, t_true, SIMPLIFY = FALSE)
    
  intersectSeveral <- function(...) { Reduce(function(x, y) { intersect(x, y) }, list(...)[[1]]) }
  t_full_intersected <- lapply(t_full, function(x) x[intersectSeveral(lapply(t_true, names))])
  t_true_intersected <- lapply(t_true, function(x) x[intersectSeveral(lapply(t_true, names))])
  
  mapply(z.prop, t_true_intersected[[1]], t_true_intersected[[2]], t_full_intersected[[1]], t_full_intersected[[2]])
}

AGE

9 AGE

df <- lapply((1:9), function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
df <- df.processing(df)
#df <- append(df, list(read.csv("../1_SAM13306969.csv", header = T, sep = "\t")))#, read.csv("2_SAM13306970.csv", header = T, sep = "\t")))

age.barcodes <- cor.clavage.gen.all(df)
age.barcodes
## $V
##                 [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
## IGHV1-18   0.7866901 0.8676775 0.8408767 0.8962367 0.9135256 0.8467400
## IGHV1-24   0.8757811 0.9205714 0.9209825 0.9346610 0.9474419 0.9231508
## IGHV1-46   0.8038785 0.8516271 0.8649374 0.9291234 0.9276555 0.8429675
## IGHV1-69   0.8744349 0.8948318 0.8895833 0.9187421 0.9464275 0.9037582
## IGHV1-8    0.8043278 0.8685702 0.8450377 0.8976584 0.9056506 0.8429392
## IGHV2-5    0.8636846 0.8312193 0.8254593 0.8036322 0.9765267 0.9742178
## IGHV3-15   0.8418605 0.9347561 0.8368942 0.9458757 0.9667527 0.8302353
## IGHV3-21   0.4428620 0.5229252 0.4523885 0.4828743 0.4894013 0.4249774
## IGHV3-23   0.8304059 0.9375092 0.7875325 0.9532873 0.9531147 0.8635335
## IGHV3-30   0.4564375 0.4731376 0.4515246 0.4702327 0.4400000 0.4369748
## IGHV3-48   0.4340018 0.5528994 0.5204327 0.5690848 0.5492892 0.6341181
## IGHV3-53   0.8101290 0.9240363 0.7174907 0.8975090 0.8636491 0.6763687
## IGHV3-7    0.4498580 0.6782686 0.5835363 0.6871555 0.5048272 0.6531355
## IGHV3-9    0.6174950 0.6444657 0.5587189 0.6339163 0.6375487 0.6408030
## IGHV4-30-2 0.8920283 0.8037553 0.9103393 0.9041160 0.8644295 0.8016586
## IGHV4-34   0.5229749 0.5603369 0.5847672 0.5448406 0.5342012 0.5077778
## IGHV4-59   0.6660821 0.7182355 0.6622561 0.7145765 0.7027285 0.7383586
## IGHV5-51   0.6615718 0.7141322 0.6721643 0.7193494 0.4855107 0.6925413
## IGHV6-1    0.5087516 0.5455333 0.6476154 0.5336538 0.5493534 0.4726879
##                 [,7]      [,8]      [,9]
## IGHV1-18   0.8744126 0.8585143 0.9056625
## IGHV1-24   0.9250150 0.9238698 0.9549509
## IGHV1-46   0.7858729 0.8643076 0.9217179
## IGHV1-69   0.8089921 0.9034166 0.9267966
## IGHV1-8    0.8792481 0.8430191 0.8877330
## IGHV2-5    0.8798037 0.8723982 0.9794262
## IGHV3-15   0.9229811 0.9129624 0.9609705
## IGHV3-21   0.5385158 0.4774205 0.5388730
## IGHV3-23   0.9241977 0.8933341 0.9724270
## IGHV3-30   0.5104031 0.4586279 0.4816737
## IGHV3-48   0.5619570 0.5249465 0.5457399
## IGHV3-53   0.8108835 0.8976570 0.9467012
## IGHV3-7    0.5403288 0.5653457 0.7130862
## IGHV3-9    0.6855104 0.6972346 0.7009312
## IGHV4-30-2 0.8106086 0.9496222 0.8597076
## IGHV4-34   0.5326061 0.5250905 0.5105924
## IGHV4-59   0.6727293 0.6944126 0.7558222
## IGHV5-51   0.5151550 0.7085772 0.4083688
## IGHV6-1    0.5941188 0.4975962 0.5037491
## 
## $`D left`
##                    [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
## IGHD1-1       0.7302369 0.7929462 0.6869251 0.7811966 0.7997635 0.7199143
## IGHD1-14      0.9986011 0.9748634 1.0000000 0.9955411 0.9937028 0.9979449
## IGHD1-20      0.9693725 0.9594716 0.9880240 0.9554164 0.9777526 0.9637131
## IGHD1-26      0.9614827 0.9749025 0.9617196 0.9553128 0.9396857 0.9712139
## IGHD1-7       0.9546577 0.9389427 0.9640107 0.9262573 0.9379252 0.9481470
## IGHD2-15      0.9226936 0.9271025 0.9277961 0.9303956 0.9181582 0.9083898
## IGHD2-2       0.9063483 0.8955736 0.9230877 0.9338078 0.9104151 0.9176086
## IGHD2-21      0.9599376 0.9663292 0.9824428 0.9268313 0.9628792 0.9404927
## IGHD2-8       0.9720623 0.9541739 0.9724560 0.9461343 0.9490889 0.9561011
## IGHD2/OR15-2b 0.9255495 0.9212048 0.8753368 0.8276892 0.9105185 0.8293413
## IGHD3-10      0.9328599 0.9313525 0.9336036 0.9235176 0.9398669 0.9152886
## IGHD3-16      0.9707824 0.9806381 0.9861641 0.9716981 0.9855581 0.9749803
## IGHD3-22      0.8438200 0.8868789 0.8847841 0.8427868 0.8802465 0.8491813
## IGHD3-3       0.8726632 0.9093480 0.8917775 0.8783273 0.8900806 0.8923056
## IGHD3-9       0.9293419 0.9166366 0.9403135 0.8686778 0.9052992 0.9029475
## IGHD3/OR15-3b 0.9988304 0.9934560 1.0000000 0.9962459 0.9970337 0.9897799
## IGHD4-11      0.8483440 0.8941931 0.9277938 0.8043127 0.8361524 0.8532982
## IGHD4-17      0.8703934 0.8982910 0.8784188 0.8525713 0.8422688 0.8608368
## IGHD4-23      0.9599767 0.9362756 0.9652735 0.9291182 0.9395480 0.9388141
## IGHD5-12      0.8723573 0.9457384 0.9197736 0.8993855 0.9418223 0.8935121
## IGHD5-24      0.8998136 0.9088476 0.9239027 0.8828320 0.9386435 0.8920934
## IGHD5-5       0.7342442 0.7443938 0.7838756 0.7686781 0.8747110 0.7681175
## IGHD6-13      0.9406273 0.9093684 0.9391543 0.9271201 0.9256587 0.9390319
## IGHD6-19      0.9145267 0.8786491 0.9316230 0.9076912 0.9200634 0.9156848
## IGHD6-25      0.9611962 0.9585921 0.9755455 0.9767892 0.9651416 0.9599739
## IGHD6-6       0.8837354 0.8306063 0.9038879 0.8582249 0.8779604 0.8567079
## IGHD7-27      0.9439182 0.8298007 0.9048655 0.9496550 0.8431892 0.9248350
##                    [,7]      [,8]      [,9]
## IGHD1-1       0.7747011 0.6777016 0.7049410
## IGHD1-14      0.9883312 1.0000000 0.9925127
## IGHD1-20      0.9761166 0.9848297 0.9708437
## IGHD1-26      0.9583254 0.9576107 0.9477227
## IGHD1-7       0.9178746 0.9212883 0.9102770
## IGHD2-15      0.9320505 0.9279912 0.8905629
## IGHD2-2       0.8889621 0.9154033 0.8899486
## IGHD2-21      0.9536653 0.9451097 0.9715891
## IGHD2-8       0.9657028 0.9816507 0.9025213
## IGHD2/OR15-2b 0.8580540 0.9448129 0.9369927
## IGHD3-10      0.9255558 0.9228755 0.8928524
## IGHD3-16      0.9805087 0.9857253 0.9817807
## IGHD3-22      0.8957961 0.8791034 0.8558406
## IGHD3-3       0.8979714 0.9034413 0.8386442
## IGHD3-9       0.9132977 0.9182060 0.8424624
## IGHD3/OR15-3b 0.9985390 0.9970770 1.0000000
## IGHD4-11      0.8478505 0.8213075 0.8564440
## IGHD4-17      0.8678978 0.8884048 0.8505441
## IGHD4-23      0.9259471 0.9748549 0.9530026
## IGHD5-12      0.9138999 0.9275705 0.9070943
## IGHD5-24      0.9470207 0.8771631 0.9149186
## IGHD5-5       0.7891719 0.7006169 0.7590775
## IGHD6-13      0.9352467 0.9277047 0.9088901
## IGHD6-19      0.9112728 0.9159302 0.8958713
## IGHD6-25      0.9458080 0.9564679 0.9368922
## IGHD6-6       0.8794259 0.8992151 0.8271263
## IGHD7-27      0.9161735 0.9429796 0.8922514
## 
## $`D right`
##                    [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
## IGHD1-1       0.8745009 0.8926725 0.9168857 0.7961538 0.9239259 0.7965711
## IGHD1-14      0.7952903 0.8565574 0.7816712 0.7952979 0.7113350 0.7605836
## IGHD1-20      0.4946470 0.4905434 0.3892216 0.3754606 0.5298524 0.3192686
## IGHD1-26      0.9081940 0.8963567 0.9045113 0.8948723 0.8818614 0.8690233
## IGHD1-7       0.6464207 0.5833136 0.5995261 0.5304324 0.6007267 0.5832174
## IGHD2-15      0.8926723 0.8387905 0.9444678 0.8864377 0.8792453 0.8880813
## IGHD2-2       0.9298114 0.9516163 0.9536189 0.9606723 0.9342986 0.9508348
## IGHD2-21      0.9252777 0.9278653 0.9491367 0.9153322 0.9226651 0.9102578
## IGHD2-8       0.9794732 0.9955196 0.9971308 0.9887199 0.9816833 0.9883755
## IGHD2/OR15-2b 0.9726190 0.9787188 0.9786921 0.9892928 0.9951111 0.9609813
## IGHD3-10      0.9754224 0.9662527 0.9762152 0.9812088 0.9899726 0.9763833
## IGHD3-16      0.9911824 0.9882987 0.9950217 0.9934785 0.9912896 0.9802075
## IGHD3-22      0.8834814 0.9070201 0.8616620 0.8816946 0.8983715 0.8686100
## IGHD3-3       0.9797963 0.9866824 0.9809019 0.9837658 0.9818029 0.9855082
## IGHD3-9       0.9903935 0.9938094 0.9988802 0.9894464 0.9944926 0.9971488
## IGHD3/OR15-3b 1.0000000 1.0000000 0.9931902 0.9967152 0.9933259 1.0000000
## IGHD4-11      0.7661410 0.7555219 0.7180596 0.7274461 0.6751579 0.6898857
## IGHD4-17      0.6282416 0.6376899 0.5551657 0.5746680 0.4810800 0.5466667
## IGHD4-23      0.7944258 0.7200215 0.7248002 0.7543238 0.7841808 0.7975796
## IGHD5-12      0.9409013 0.9554744 0.9005480 0.9464368 0.9396641 0.9382590
## IGHD5-24      0.9230579 0.9426952 0.9389132 0.9417461 0.9439414 0.9022913
## IGHD5-5       0.8249909 0.8025116 0.7876136 0.8240247 0.8492775 0.8159164
## IGHD6-13      0.6978680 0.7325093 0.7171781 0.7127487 0.6717716 0.6678213
## IGHD6-19      0.7478362 0.7811939 0.7719029 0.7219719 0.7514751 0.7605409
## IGHD6-25      0.8606031 0.6542443 0.7757713 0.8181818 0.7827160 0.7752882
## IGHD6-6       0.7194780 0.7267673 0.7083713 0.7438338 0.7341847 0.7350521
## IGHD7-27      0.5067829 0.6233427 0.4543117 0.4682081 0.4936746 0.5386139
##                    [,7]      [,8]      [,9]
## IGHD1-1       0.9022932 0.8846063 0.8167634
## IGHD1-14      0.7662027 0.8476802 0.7091944
## IGHD1-20      0.4404264 0.5904025 0.2791563
## IGHD1-26      0.9188961 0.9013858 0.8744208
## IGHD1-7       0.6236769 0.6612987 0.5089384
## IGHD2-15      0.8948338 0.8337810 0.9077172
## IGHD2-2       0.9488914 0.9691396 0.9589372
## IGHD2-21      0.9318451 0.8906983 0.9131997
## IGHD2-8       0.9939192 0.9950864 0.9823763
## IGHD2/OR15-2b 0.9916599 0.9972469 0.9961555
## IGHD3-10      0.9812493 0.9804353 0.9723900
## IGHD3-16      0.9892219 0.9732696 0.9882294
## IGHD3-22      0.8994053 0.8826030 0.8798109
## IGHD3-3       0.9875172 0.9828849 0.9764242
## IGHD3-9       0.9962109 0.9990904 0.9921672
## IGHD3/OR15-3b 1.0000000 0.9991880 1.0000000
## IGHD4-11      0.7386912 0.7104116 0.6708288
## IGHD4-17      0.5253124 0.5953604 0.5060710
## IGHD4-23      0.8443518 0.8401618 0.8269642
## IGHD5-12      0.9540905 0.9330289 0.9278717
## IGHD5-24      0.8880402 0.9119191 0.9381787
## IGHD5-5       0.7991230 0.8260336 0.8396137
## IGHD6-13      0.7048801 0.7206094 0.6917549
## IGHD6-19      0.7748518 0.7481964 0.7238376
## IGHD6-25      0.7791051 0.8522385 0.5826609
## IGHD6-6       0.7622034 0.7267660 0.6997268
## IGHD7-27      0.5275048 0.5042872 0.5523778
## 
## $J
##            [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
## IGHJ1 0.9592021 0.9161693 0.9263415 0.9257330 0.8751184 0.9122098
## IGHJ2 0.9392378 0.9108943 0.8901226 0.8740516 0.9054208 0.9786092
## IGHJ4 0.8989200 0.8835550 0.8774928 0.8777778 0.8930896 0.8811566
## IGHJ5 0.9162756 0.8854780 0.9151024 0.9081968 0.9052664 0.8975838
## IGHJ6 0.9493617 0.9449638 0.9520273 0.9580570 0.9539038 0.9356576
##            [,7]      [,8]      [,9]
## IGHJ1 0.8948747 0.9550015 0.8500783
## IGHJ2 0.9306224 0.8816646 0.8542163
## IGHJ4 0.8903390 0.8893345 0.8792691
## IGHJ5 0.9092522 0.9233544 0.9055160
## IGHJ6 0.9538703 0.9559250 0.9482402
pairs.plots(age.barcodes)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(age.barcodes, cor)
l_ply(corr, corrplot, method="number")

corr <- lapply(age.barcodes, cor, method = "spearman")
l_ply(corr, corrplot, method="number")

df <- lapply((1:9), function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
#df <- append(df, list(read.csv("../1_SAM13306969.csv", header = T, sep = "\t")))#, read.csv("2_SAM13306970.csv", header = T, sep = "\t")))
df <- list(Reduce(function(...) merge(..., all=T), df[1:4]), Reduce(function(...) merge(..., all=T), df[5:9]))
df <- df.processing(df)

age.barcodes.reduced.eq  <- cor.clavage.gen.all(df)
age.barcodes.reduced.eq
## $V
##                 [,1]      [,2]
## IGHV1-18   0.8475916 0.8773377
## IGHV1-2    0.7923364 0.7720195
## IGHV1-24   0.9140113 0.9329558
## IGHV1-3    0.9087093 0.9095657
## IGHV1-46   0.8522564 0.8647534
## IGHV1-58   0.6106470 0.6264801
## IGHV1-69   0.8938054 0.9063132
## IGHV1-8    0.8431381 0.8771232
## IGHV2-26   0.7682061 0.7614922
## IGHV2-5    0.8302468 0.9261562
## IGHV2-70   0.7916723 0.8280419
## IGHV3-11   0.5665359 0.5830431
## IGHV3-13   0.7478261 0.8515994
## IGHV3-15   0.8947798 0.9108505
## IGHV3-21   0.4700790 0.4986732
## IGHV3-23   0.8879589 0.9211838
## IGHV3-30   0.4631445 0.4689918
## IGHV3-30-3 0.2031245 0.2289615
## IGHV3-33   0.3827804 0.4034180
## IGHV3-43   0.6329261 0.6793173
## IGHV3-48   0.5192867 0.5743029
## IGHV3-49   0.7932803 0.9088428
## IGHV3-53   0.8393913 0.8306923
## IGHV3-66   0.4121155 0.4083463
## IGHV3-7    0.5772761 0.5957899
## IGHV3-73   0.8448767 0.8858723
## IGHV3-74   0.6028708 0.6222808
## IGHV3-9    0.6186746 0.6716225
## IGHV4-30-2 0.8711424 0.8440871
## IGHV4-30-4 0.6571858 0.6777614
## IGHV4-31   0.6259177 0.6928823
## IGHV4-34   0.5536250 0.5207286
## IGHV4-39   0.6004331 0.6013421
## IGHV4-4    0.5940031 0.7249386
## IGHV4-59   0.6936416 0.7145550
## IGHV4-61   0.6348315 0.6102829
## IGHV4-b    0.1970823 0.1999463
## IGHV5-51   0.6911728 0.5632644
## IGHV5-a    0.2580572 0.2600285
## IGHV6-1    0.5427831 0.5220548
## 
## $`D left`
##                    [,1]      [,2]
## IGHD1-1       0.7422005 0.7409508
## IGHD1-14      0.9911173 0.9937016
## IGHD1-20      0.9686690 0.9732143
## IGHD1-26      0.9642715 0.9577031
## IGHD1-7       0.9464658 0.9279045
## IGHD1/OR15-1b 0.9861298 0.9884272
## IGHD2-15      0.9260051 0.9154578
## IGHD2-2       0.9114973 0.9031093
## IGHD2-21      0.9613537 0.9526162
## IGHD2-8       0.9634678 0.9539035
## IGHD2/OR15-2b 0.9029168 0.8846575
## IGHD3-10      0.9309025 0.9170276
## IGHD3-16      0.9758877 0.9812874
## IGHD3-22      0.8592245 0.8712126
## IGHD3-3       0.8870608 0.8844551
## IGHD3-9       0.9171554 0.8982805
## IGHD3/OR15-3b 0.9975140 0.9965454
## IGHD4-11      0.8640873 0.8452222
## IGHD4-17      0.8770615 0.8620563
## IGHD4-23      0.9489534 0.9437763
## IGHD4/OR15-4b 0.8158899 0.8386426
## IGHD5-12      0.9098803 0.9152817
## IGHD5-24      0.9022143 0.9144533
## IGHD5-5       0.7511756 0.7617954
## IGHD5/OR15-5b 1.0000000 0.9994804
## IGHD6-13      0.9271930 0.9281486
## IGHD6-19      0.9052707 0.9116866
## IGHD6-25      0.9657638 0.9527170
## IGHD6-6       0.8627859 0.8668404
## IGHD7-27      0.9025671 0.9068297
## 
## $`D right`
##                    [,1]      [,2]
## IGHD1-1       0.8748378 0.8660996
## IGHD1-14      0.8115068 0.7592054
## IGHD1-20      0.4541785 0.4121592
## IGHD1-26      0.9020872 0.8914628
## IGHD1-7       0.5996778 0.5984960
## IGHD1/OR15-1b 0.5812081 0.5184071
## IGHD2-15      0.8850346 0.8846502
## IGHD2-2       0.9449366 0.9539488
## IGHD2-21      0.9299032 0.9152387
## IGHD2-8       0.9887404 0.9893660
## IGHD2/OR15-2b 0.9778582 0.9862087
## IGHD3-10      0.9739411 0.9788770
## IGHD3-16      0.9914659 0.9842580
## IGHD3-22      0.8853515 0.8835970
## IGHD3-3       0.9826620 0.9832630
## IGHD3-9       0.9924671 0.9959062
## IGHD3/OR15-3b 0.9983962 0.9989263
## IGHD4-11      0.7510077 0.6997904
## IGHD4-17      0.6137414 0.5302145
## IGHD4-23      0.7554244 0.8200344
## IGHD4/OR15-4b 0.9341323 0.8643766
## IGHD5-12      0.9402887 0.9402856
## IGHD5-24      0.9330153 0.9106300
## IGHD5-5       0.8126582 0.8207147
## IGHD5/OR15-5b 1.0000000 0.9981164
## IGHD6-13      0.7153594 0.6918569
## IGHD6-19      0.7569385 0.7540794
## IGHD6-25      0.7897139 0.7621415
## IGHD6-6       0.7249832 0.7336492
## IGHD7-27      0.5299971 0.5226469
## 
## $J
##            [,1]      [,2]
## IGHJ1 0.9377571 0.9046791
## IGHJ2 0.9079024 0.9484968
## IGHJ3 0.9941813 0.9673792
## IGHJ4 0.8865449 0.8859708
## IGHJ5 0.9073937 0.9072817
## IGHJ6 0.9495385 0.9478018
pairs.plots(age.barcodes.reduced.eq)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(age.barcodes.reduced.eq, cor)
l_ply(corr, corrplot, method="number")

corr <- lapply(age.barcodes.reduced.eq, cor, method = "spearman")
l_ply(corr, corrplot, method="number")

N <- 1000
out <- lapply(age.barcodes.reduced.eq, function(x) {
      c(cor(x[,1], x[,2]), replicate(N, permutation.test(x[,1], x[,2], length(df)))) 
    }
  )
lapply(out, function(x) {
    print(hist(x))
    print(abline(v=x[1], col='red'))
  }
)

## $breaks
##  [1] -0.5 -0.4 -0.3 -0.2 -0.1  0.0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8
## [15]  0.9  1.0
## 
## $counts
##  [1]   5  24  74 169 227 232 159  81  23   5   1   0   0   0   1
## 
## $density
##  [1] 0.04995005 0.23976024 0.73926074 1.68831169 2.26773227 2.31768232
##  [7] 1.58841159 0.80919081 0.22977023 0.04995005 0.00999001 0.00000000
## [13] 0.00000000 0.00000000 0.00999001
## 
## $mids
##  [1] -0.45 -0.35 -0.25 -0.15 -0.05  0.05  0.15  0.25  0.35  0.45  0.55
## [12]  0.65  0.75  0.85  0.95
## 
## $xname
## [1] "x"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"
## NULL

## $breaks
##  [1] -0.5 -0.4 -0.3 -0.2 -0.1  0.0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8
## [15]  0.9  1.0
## 
## $counts
##  [1]  10  36  85 158 215 197 160  75  38  21   5   0   0   0   1
## 
## $density
##  [1] 0.09990010 0.35964036 0.84915085 1.57842158 2.14785215 1.96803197
##  [7] 1.59840160 0.74925075 0.37962038 0.20979021 0.04995005 0.00000000
## [13] 0.00000000 0.00000000 0.00999001
## 
## $mids
##  [1] -0.45 -0.35 -0.25 -0.15 -0.05  0.05  0.15  0.25  0.35  0.45  0.55
## [12]  0.65  0.75  0.85  0.95
## 
## $xname
## [1] "x"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"
## NULL

## $breaks
##  [1] -0.6 -0.5 -0.4 -0.3 -0.2 -0.1  0.0  0.1  0.2  0.3  0.4  0.5  0.6  0.7
## [15]  0.8  0.9  1.0
## 
## $counts
##  [1]   1  12  44  93 178 197 187 127  89  46  17   7   2   0   0   1
## 
## $density
##  [1] 0.00999001 0.11988012 0.43956044 0.92907093 1.77822178 1.96803197
##  [7] 1.86813187 1.26873127 0.88911089 0.45954046 0.16983017 0.06993007
## [13] 0.01998002 0.00000000 0.00000000 0.00999001
## 
## $mids
##  [1] -0.55 -0.45 -0.35 -0.25 -0.15 -0.05  0.05  0.15  0.25  0.35  0.45
## [12]  0.55  0.65  0.75  0.85  0.95
## 
## $xname
## [1] "x"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"
## NULL

## $breaks
##  [1] -1.0 -0.8 -0.6 -0.4 -0.2  0.0  0.2  0.4  0.6  0.8  1.0
## 
## $counts
##  [1]  24  88 127 122 153 135 109 139  79  25
## 
## $density
##  [1] 0.1198801 0.4395604 0.6343656 0.6093906 0.7642358 0.6743257 0.5444555
##  [8] 0.6943057 0.3946054 0.1248751
## 
## $mids
##  [1] -0.9 -0.7 -0.5 -0.3 -0.1  0.1  0.3  0.5  0.7  0.9
## 
## $xname
## [1] "x"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"
## NULL
## $V
## NULL
## 
## $`D left`
## NULL
## 
## $`D right`
## NULL
## 
## $J
## NULL
zt <- z.test(df = df, Type.segment = "V", threshold = 1000)
shapiro.test(zt)
## 
##  Shapiro-Wilk normality test
## 
## data:  zt
## W = 0.88551, p-value = 0.0007437

SAM

#df <- lapply((1:9)[-5], function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
df <- list(read.csv("../1_SAM13306969.csv", header = T, sep = "\t"), read.csv("../2_SAM13306970.csv", header = T, sep = "\t"))
#df <- list(Reduce(function(...) merge(..., all=T), df[1:4]), Reduce(function(...) merge(..., all=T), df[5:10]))
df <- df.processing(df, threshold.perc.identity = 95)

sam.dataset  <- cor.clavage.gen.all(df)
sam.dataset
## $V
##                [,1]      [,2]
## IGHV1-69  0.5940065 0.6622961
## IGHV3-7   0.7069960 0.6985434
## IGHV5-51  0.8566597 0.7391533
## IGHV7-4-1 0.6623468 0.5878084
## 
## $`D left`
##               [,1]      [,2]
## IGHD1-26 0.9619005 0.9671764
## IGHD2-15 0.9733426 0.9674895
## IGHD2-2  0.8981395 0.9715536
## IGHD2-21 0.9858907 0.9570776
## IGHD3-10 0.9745923 0.9279201
## IGHD3-16 0.9950562 1.0000000
## IGHD3-22 0.9644709 0.8949495
## IGHD3-9  0.9803823 0.8959828
## IGHD5-12 0.9335154 0.9056277
## IGHD6-13 0.9873328 0.9272896
## IGHD6-19 0.9631646 0.9096937
## 
## $`D right`
##               [,1]      [,2]
## IGHD1-26 0.9340352 0.9328609
## IGHD2-15 0.9397089 0.9494281
## IGHD2-2  0.9227309 0.9545952
## IGHD3-10 0.9855736 0.9722102
## IGHD3-16 0.9908614 0.9965636
## IGHD3-22 0.8303010 0.9232323
## IGHD3-9  0.9895549 0.9956958
## IGHD5-12 0.9450758 0.9290043
## IGHD6-13 0.7897780 0.6191213
## IGHD6-19 0.8382193 0.7597095
## 
## $J
##            [,1]      [,2]
## IGHJ1 0.9320535 0.9540317
## IGHJ2 0.9337022 0.8439099
## IGHJ3 0.7844543 0.6726097
## IGHJ4 0.9292841 0.8971837
## IGHJ5 0.9643401 0.9369254
## IGHJ6 0.9922409 0.9549284
pairs.plots(sam.dataset)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(sam.dataset, cor)
corr
## $V
##           [,1]      [,2]
## [1,] 1.0000000 0.6946352
## [2,] 0.6946352 1.0000000
## 
## $`D left`
##            [,1]       [,2]
## [1,] 1.00000000 0.02868389
## [2,] 0.02868389 1.00000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8525457
## [2,] 0.8525457 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.9382013
## [2,] 0.9382013 1.0000000
l_ply(corr, corrplot, method="number")

corr <- lapply(sam.dataset, cor, method = "spearman")
corr
## $V
##      [,1] [,2]
## [1,]  1.0  0.8
## [2,]  0.8  1.0
## 
## $`D left`
##      [,1] [,2]
## [1,]  1.0  0.1
## [2,]  0.1  1.0
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8787879
## [2,] 0.8787879 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.7142857
## [2,] 0.7142857 1.0000000
l_ply(corr, corrplot, method="number")

#df <- lapply((1:9)[-5], function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
df <- list(read.csv("../7_SAM15574987.csv", header = T, sep = "\t"), read.csv("../8_SAM15574988.csv", header = T, sep = "\t"))
#df <- list(Reduce(function(...) merge(..., all=T), df[1:4]), Reduce(function(...) merge(..., all=T), df[5:10]))
df <- df.processing(df, threshold.perc.identity = 95)

sam.dataset  <- cor.clavage.gen.all(df)
sam.dataset
## $V
##                 [,1]      [,2]
## IGHV1-18   0.4036657 0.7189098
## IGHV1-2    0.6382992 0.7301821
## IGHV1-24   0.7138580 0.8307475
## IGHV1-3    0.8698738 0.8145363
## IGHV1-46   0.6147152 0.8020765
## IGHV1-69   0.5411282 0.5480840
## IGHV1-8    0.7145349 0.6512566
## IGHV2-5    0.8922812 0.6616142
## IGHV3-11   0.6896825 0.7128049
## IGHV3-15   0.6236537 0.7737632
## IGHV3-21   0.5051322 0.3358586
## IGHV3-23   0.5405208 0.5709509
## IGHV3-30   0.4362958 0.4239319
## IGHV3-30-3 0.7114574 0.7888686
## IGHV3-33   0.3782211 0.3490412
## IGHV3-48   0.4472986 0.6605480
## IGHV3-66   0.6803028 0.4768737
## IGHV3-7    0.7335840 0.5881797
## IGHV3-72   0.9760110 0.7822773
## IGHV3-73   0.8349719 0.9392208
## IGHV3-74   0.6038819 0.5522343
## IGHV3-9    0.5759742 0.7846688
## IGHV4-39   0.6327101 0.7846443
## IGHV4-59   0.6365857 0.6913296
## IGHV4-61   0.6030097 0.8014528
## IGHV5-51   0.5976193 0.6250401
## IGHV5-a    0.2422374 0.2671958
## IGHV6-1    0.5704027 0.6230786
## IGHV7-4-1  0.4631988 0.7724289
## 
## $`D left`
##                    [,1]      [,2]
## IGHD1-1       0.8790740 0.7763049
## IGHD1-14      1.0000000 0.9755639
## IGHD1-20      0.9972848 0.8954337
## IGHD1-26      0.9248803 0.9632203
## IGHD1-7       0.9688131 0.7235032
## IGHD2-15      0.9531008 0.9677125
## IGHD2-2       0.8985081 0.8514273
## IGHD2-21      0.9716642 0.9826370
## IGHD2-8       0.9610356 0.9899757
## IGHD2/OR15-2b 0.9724402 0.9222136
## IGHD3-10      0.9584325 0.9687005
## IGHD3-16      0.9932721 0.9874362
## IGHD3-22      0.9263553 0.8379662
## IGHD3-3       0.9076984 0.9339710
## IGHD3-9       0.9476856 0.9206804
## IGHD3/OR15-3b 0.9978869 1.0000000
## IGHD4-11      0.9143039 0.7230143
## IGHD4-17      0.9323821 0.9192585
## IGHD4-23      0.9811447 0.9321999
## IGHD4/OR15-4b 0.8318943 0.7260355
## IGHD5-12      0.9777678 0.9539309
## IGHD5-24      0.9732704 0.9346332
## IGHD5-5       0.8956436 0.8628078
## IGHD5/OR15-5b 1.0000000 0.9853372
## IGHD6-13      0.8954583 0.9233718
## IGHD6-19      0.9532937 0.9691607
## IGHD6-25      0.9878299 0.9554910
## IGHD6-6       0.9253247 0.7354131
## IGHD7-27      0.9678692 0.9596091
## 
## $`D right`
##                    [,1]      [,2]
## IGHD1-1       0.8955224 0.9034797
## IGHD1-20      0.2256047 0.4763577
## IGHD1-26      0.9444470 0.9114610
## IGHD1-7       0.6309177 0.8824839
## IGHD2-15      0.8916021 0.9436768
## IGHD2-2       0.9554995 0.9768026
## IGHD2-21      0.9459955 0.9626453
## IGHD2-8       0.9883495 0.9882572
## IGHD2/OR15-2b 0.9913486 0.9926471
## IGHD3-10      0.9874923 0.9919184
## IGHD3-16      0.9971107 0.9987817
## IGHD3-22      0.9050572 0.9489441
## IGHD3-3       0.9736448 0.9814255
## IGHD3-9       0.9894967 0.9931757
## IGHD3/OR15-3b 0.9987570 1.0000000
## IGHD4-11      0.8768716 0.9294297
## IGHD4-17      0.6246168 0.4142122
## IGHD4-23      0.9254881 0.8547141
## IGHD4/OR15-4b 0.9314537 0.9177515
## IGHD5-12      0.9635628 0.9748336
## IGHD5-24      0.9573497 0.9360526
## IGHD5-5       0.7564197 0.7594673
## IGHD5/OR15-5b 0.9883398 1.0000000
## IGHD6-13      0.8503846 0.7196842
## IGHD6-19      0.8136450 0.7836964
## IGHD6-25      0.8256529 0.7527818
## IGHD6-6       0.5393669 0.5846495
## IGHD7-27      0.6295225 0.5705755
## 
## $J
##            [,1]      [,2]
## IGHJ1 0.9707982 0.9363661
## IGHJ2 0.6766561 0.8656658
## IGHJ3 0.7787406 0.8182883
## IGHJ4 0.9322555 0.8437726
## IGHJ5 0.9465292 0.9384172
## IGHJ6 0.9834185 0.9786968
pairs.plots(sam.dataset)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(sam.dataset, cor)
corr
## $V
##           [,1]      [,2]
## [1,] 1.0000000 0.5981172
## [2,] 0.5981172 1.0000000
## 
## $`D left`
##           [,1]      [,2]
## [1,] 1.0000000 0.6239273
## [2,] 0.6239273 1.0000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8713379
## [2,] 0.8713379 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.6690805
## [2,] 0.6690805 1.0000000
l_ply(corr, corrplot, method="number")

corr <- lapply(sam.dataset, cor, method = "spearman")
corr
## $V
##          [,1]     [,2]
## [1,] 1.000000 0.526601
## [2,] 0.526601 1.000000
## 
## $`D left`
##           [,1]      [,2]
## [1,] 1.0000000 0.5995812
## [2,] 0.5995812 1.0000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.9418366
## [2,] 0.9418366 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.7714286
## [2,] 0.7714286 1.0000000
l_ply(corr, corrplot, method="number")

#df <- lapply((1:9)[-5], function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
df <- list(read.csv("../1_SAM13306969.csv", header = T, sep = "\t"), read.csv("../7_SAM15574987.csv", header = T, sep = "\t"))
#df <- list(Reduce(function(...) merge(..., all=T), df[1:4]), Reduce(function(...) merge(..., all=T), df[5:10]))
df <- df.processing(df, threshold.perc.identity = 98)

sam.dataset  <- cor.clavage.gen.all(df)
sam.dataset
## $V
##                [,1]      [,2]
## IGHV1-18  0.6443760 0.2578000
## IGHV1-8   0.4340409 0.7934386
## IGHV3-23  0.4138462 0.5859408
## IGHV3-7   0.7492063 0.8070053
## IGHV3-74  0.8283401 0.5407609
## IGHV3-9   0.7720829 0.4619883
## IGHV5-51  0.9188824 0.7026714
## IGHV7-4-1 0.6981919 0.8115311
## 
## $`D left`
##                    [,1]      [,2]
## IGHD1-1       0.8347199 0.8790740
## IGHD1-14      0.9877142 1.0000000
## IGHD1-20      1.0000000 0.9972848
## IGHD1-26      0.9619005 0.9248803
## IGHD1-7       0.9267315 0.9688131
## IGHD1/OR15-1b 1.0000000 1.0000000
## IGHD2-15      0.9743065 0.9543387
## IGHD2-2       0.9062081 0.9003247
## IGHD2-21      0.9912531 0.9751107
## IGHD2-8       1.0000000 0.9607996
## IGHD2/OR15-2b 0.9623514 0.9724402
## IGHD3-10      0.9760981 0.9631566
## IGHD3-16      0.9948770 0.9925045
## IGHD3-22      0.9721325 0.9427218
## IGHD3-3       0.9275921 0.9133652
## IGHD3-9       0.9864732 0.9559956
## IGHD3/OR15-3b 0.9527193 1.0000000
## IGHD4-11      0.8260082 0.9143039
## IGHD4-17      0.7959147 0.9323821
## IGHD4-23      0.9375361 0.9811447
## IGHD4/OR15-4b 0.8458260 0.8318943
## IGHD5-12      0.9385612 0.9778624
## IGHD5-24      0.9547564 0.9732704
## IGHD5-5       0.7598867 0.8970419
## IGHD5/OR15-5b 1.0000000 1.0000000
## IGHD6-13      0.9888997 0.8992956
## IGHD6-19      0.9638206 0.9554246
## IGHD6-25      0.9967506 0.9878299
## IGHD6-6       0.9383320 0.9253247
## IGHD7-27      0.9549995 0.9678692
## 
## $`D right`
##                    [,1]      [,2]
## IGHD1-1       0.8621742 0.8955224
## IGHD1-14      0.7241013 0.5673583
## IGHD1-20      0.4843059 0.2256047
## IGHD1-26      0.9340352 0.9444470
## IGHD1-7       0.8065710 0.6309177
## IGHD2-15      0.9412023 0.8890304
## IGHD2-2       0.9201342 0.9532233
## IGHD2-21      0.9691623 0.9484704
## IGHD2-8       0.9958143 0.9882790
## IGHD2/OR15-2b 0.9953765 0.9913486
## IGHD3-10      0.9883337 0.9886974
## IGHD3-16      0.9922378 0.9967811
## IGHD3-22      0.8283570 0.9234864
## IGHD3-3       0.9942494 0.9758013
## IGHD3-9       0.9889198 0.9903190
## IGHD3/OR15-3b 1.0000000 0.9987375
## IGHD4-11      0.8927795 0.8768716
## IGHD4-17      0.6664717 0.6246168
## IGHD4-23      0.9390214 0.9254881
## IGHD4/OR15-4b 0.9892710 0.9314537
## IGHD5-12      0.9481303 0.9655004
## IGHD5-24      0.7289985 0.9573497
## IGHD5-5       0.8876534 0.7576007
## IGHD5/OR15-5b 1.0000000 0.9883398
## IGHD6-13      0.7913497 0.8566397
## IGHD6-19      0.8387902 0.8201686
## IGHD6-25      0.7822908 0.8256529
## IGHD6-6       0.7826678 0.5393669
## IGHD7-27      0.5585556 0.6295225
## 
## $J
##            [,1]      [,2]
## IGHJ1 0.9635309 0.9807715
## IGHJ2 0.9423594 0.6298852
## IGHJ3 0.8145963 0.8626176
## IGHJ4 0.9464439 0.9415038
## IGHJ5 0.9728939 0.9562210
## IGHJ6 0.9921710 0.9814437
pairs.plots(sam.dataset)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(sam.dataset, cor)
corr
## $V
##             [,1]        [,2]
## [1,]  1.00000000 -0.04371395
## [2,] -0.04371395  1.00000000
## 
## $`D left`
##         [,1]    [,2]
## [1,] 1.00000 0.67671
## [2,] 0.67671 1.00000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8547721
## [2,] 0.8547721 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.2847732
## [2,] 0.2847732 1.0000000
l_ply(corr, corrplot, method="number")

corr <- lapply(sam.dataset, cor, method = "spearman")
corr
## $V
##             [,1]        [,2]
## [1,]  1.00000000 -0.07142857
## [2,] -0.07142857  1.00000000
## 
## $`D left`
##           [,1]      [,2]
## [1,] 1.0000000 0.6164994
## [2,] 0.6164994 1.0000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8614361
## [2,] 0.8614361 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.8857143
## [2,] 0.8857143 1.0000000
l_ply(corr, corrplot, method="number")

#df <- lapply((1:9)[-5], function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
df <- list(read.csv("../1_SAM13306969.csv", header = T, sep = "\t"), read.csv("../8_SAM15574988.csv", header = T, sep = "\t"))
#df <- list(Reduce(function(...) merge(..., all=T), df[1:4]), Reduce(function(...) merge(..., all=T), df[5:10]))
df <- df.processing(df, threshold.perc.identity = 98)

sam.dataset  <- cor.clavage.gen.all(df)
sam.dataset
## $V
##                [,1]      [,2]
## IGHV1-18  0.6443760 0.6829013
## IGHV1-69  0.6031022 0.5193828
## IGHV1-8   0.4340409 0.6442308
## IGHV3-23  0.4138462 0.6518862
## IGHV3-48  0.8695355 0.4741748
## IGHV3-7   0.7492063 0.7152639
## IGHV3-74  0.8283401 0.5235358
## IGHV3-9   0.7720829 0.7699855
## IGHV5-51  0.9188824 0.6282070
## IGHV7-4-1 0.6981919 0.8249928
## 
## $`D left`
##                    [,1]      [,2]
## IGHD1-1       0.8347199 0.7763049
## IGHD1-14      0.9877142 0.9755639
## IGHD1-20      1.0000000 0.8954337
## IGHD1-26      0.9619005 0.9632203
## IGHD1-7       0.9267315 0.7235032
## IGHD2-15      0.9743065 0.9704196
## IGHD2-2       0.9062081 0.8401284
## IGHD2-21      0.9912531 0.9827526
## IGHD2-8       1.0000000 0.9897661
## IGHD2/OR15-2b 0.9623514 0.9222136
## IGHD3-10      0.9760981 0.9723500
## IGHD3-16      0.9948770 0.9876989
## IGHD3-22      0.9721325 0.8363623
## IGHD3-3       0.9275921 0.9364101
## IGHD3-9       0.9864732 0.9228335
## IGHD3/OR15-3b 0.9527193 1.0000000
## IGHD4-11      0.8260082 0.7230143
## IGHD4-17      0.7959147 0.9192585
## IGHD4-23      0.9375361 0.9321999
## IGHD4/OR15-4b 0.8458260 0.7260355
## IGHD5-12      0.9385612 0.9541790
## IGHD5-24      0.9547564 0.9346332
## IGHD5-5       0.7598867 0.8640936
## IGHD5/OR15-5b 1.0000000 0.9853372
## IGHD6-13      0.9888997 0.9547091
## IGHD6-19      0.9638206 0.9703075
## IGHD6-25      0.9967506 0.9554910
## IGHD6-6       0.9383320 0.7354131
## IGHD7-27      0.9549995 0.9596091
## 
## $`D right`
##                    [,1]      [,2]
## IGHD1-1       0.8621742 0.9034797
## IGHD1-20      0.4843059 0.4763577
## IGHD1-26      0.9340352 0.9114610
## IGHD1-7       0.8065710 0.8824839
## IGHD2-15      0.9412023 0.9448637
## IGHD2-2       0.9201342 0.9758707
## IGHD2-21      0.9691623 0.9685901
## IGHD2-8       0.9958143 0.9880117
## IGHD2/OR15-2b 0.9953765 0.9926471
## IGHD3-10      0.9883337 0.9929289
## IGHD3-16      0.9922378 0.9987699
## IGHD3-22      0.8283570 0.9484541
## IGHD3-3       0.9942494 0.9812531
## IGHD3-9       0.9889198 0.9954068
## IGHD3/OR15-3b 1.0000000 1.0000000
## IGHD4-11      0.8927795 0.9294297
## IGHD4-17      0.6664717 0.4142122
## IGHD4-23      0.9390214 0.8547141
## IGHD4/OR15-4b 0.9892710 0.9177515
## IGHD5-12      0.9481303 0.9748271
## IGHD5-24      0.7289985 0.9360526
## IGHD5-5       0.8876534 0.7605991
## IGHD5/OR15-5b 1.0000000 1.0000000
## IGHD6-13      0.7913497 0.7470627
## IGHD6-19      0.8387902 0.7841926
## IGHD6-25      0.7822908 0.7527818
## IGHD6-6       0.7826678 0.5846495
## IGHD7-27      0.5585556 0.5705755
## 
## $J
##            [,1]      [,2]
## IGHJ1 0.9635309 0.9152901
## IGHJ2 0.9423594 0.8657736
## IGHJ3 0.8145963 0.8284958
## IGHJ4 0.9464439 0.8383887
## IGHJ5 0.9728939 0.9475216
## IGHJ6 0.9921710 0.9767419
pairs.plots(sam.dataset)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(sam.dataset, cor)
corr
## $V
##            [,1]       [,2]
## [1,]  1.0000000 -0.1600687
## [2,] -0.1600687  1.0000000
## 
## $`D left`
##           [,1]      [,2]
## [1,] 1.0000000 0.5870043
## [2,] 0.5870043 1.0000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8561029
## [2,] 0.8561029 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.7486685
## [2,] 0.7486685 1.0000000
l_ply(corr, corrplot, method="number")

corr <- lapply(sam.dataset, cor, method = "spearman")
corr
## $V
##            [,1]       [,2]
## [1,]  1.0000000 -0.2242424
## [2,] -0.2242424  1.0000000
## 
## $`D left`
##           [,1]      [,2]
## [1,] 1.0000000 0.6619025
## [2,] 0.6619025 1.0000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8680537
## [2,] 0.8680537 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.9428571
## [2,] 0.9428571 1.0000000
l_ply(corr, corrplot, method="number")

#df <- lapply((1:9)[-5], function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
df <- list(read.csv("../2_SAM13306970.csv", header = T, sep = "\t"), read.csv("../7_SAM15574987.csv", header = T, sep = "\t"))
#df <- list(Reduce(function(...) merge(..., all=T), df[1:4]), Reduce(function(...) merge(..., all=T), df[5:10]))
df <- df.processing(df, threshold.perc.identity = 98)

sam.dataset  <- cor.clavage.gen.all(df)
sam.dataset
## $V
##                [,1]      [,2]
## IGHV5-51  0.7440033 0.7026714
## IGHV7-4-1 0.5769683 0.8115311
## 
## $`D left`
##               [,1]      [,2]
## IGHD1-26 0.9671764 0.9248803
## IGHD2-15 0.9671133 0.9543387
## IGHD2-2  0.9704713 0.9003247
## IGHD2-21 0.9565619 0.9751107
## IGHD3-10 0.9348448 0.9631566
## IGHD3-16 1.0000000 0.9925045
## IGHD3-22 0.8958440 0.9427218
## IGHD3-9  0.8956084 0.9559956
## IGHD5-12 0.9056277 0.9778624
## IGHD6-13 0.9290143 0.8992956
## IGHD6-19 0.9096937 0.9554246
## 
## $`D right`
##               [,1]      [,2]
## IGHD1-26 0.9328609 0.9444470
## IGHD2-15 0.9488429 0.8890304
## IGHD2-2  0.9528677 0.9532233
## IGHD3-10 0.9729254 0.9886974
## IGHD3-16 0.9965636 0.9967811
## IGHD3-22 0.9271421 0.9234864
## IGHD3-9  0.9956803 0.9903190
## IGHD5-12 0.9290043 0.9655004
## IGHD6-13 0.6202728 0.8566397
## IGHD6-19 0.7597095 0.8201686
## 
## $J
##            [,1]      [,2]
## IGHJ1 0.9604520 0.9807715
## IGHJ3 0.6829488 0.8626176
## IGHJ4 0.8970930 0.9415038
## IGHJ5 0.9345740 0.9562210
## IGHJ6 0.9507971 0.9814437
pairs.plots(sam.dataset)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(sam.dataset, cor)
corr
## $V
##      [,1] [,2]
## [1,]    1   -1
## [2,]   -1    1
## 
## $`D left`
##            [,1]       [,2]
## [1,] 1.00000000 0.02840588
## [2,] 0.02840588 1.00000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8136303
## [2,] 0.8136303 1.0000000
## 
## $J
##           [,1]      [,2]
## [1,] 1.0000000 0.9860629
## [2,] 0.9860629 1.0000000
l_ply(corr, corrplot, method="number")

corr <- lapply(sam.dataset, cor, method = "spearman")
corr
## $V
##      [,1] [,2]
## [1,]    1   -1
## [2,]   -1    1
## 
## $`D left`
##             [,1]        [,2]
## [1,]  1.00000000 -0.02727273
## [2,] -0.02727273  1.00000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.8666667
## [2,] 0.8666667 1.0000000
## 
## $J
##      [,1] [,2]
## [1,]  1.0  0.9
## [2,]  0.9  1.0
l_ply(corr, corrplot, method="number")

#df <- lapply((1:9)[-5], function(i) read.csv(paste("../", i, ".csv", sep = ""), header = T, sep = "\t"))
df <- list(read.csv("../2_SAM13306970.csv", header = T, sep = "\t"), read.csv("../8_SAM15574988.csv", header = T, sep = "\t"))
#df <- list(Reduce(function(...) merge(..., all=T), df[1:4]), Reduce(function(...) merge(..., all=T), df[5:10]))
df <- df.processing(df, threshold.perc.identity = 98)

sam.dataset  <- cor.clavage.gen.all(df)
sam.dataset
## $V
##                [,1]      [,2]
## IGHV1-69  0.6634398 0.5193828
## IGHV5-51  0.7440033 0.6282070
## IGHV7-4-1 0.5769683 0.8249928
## 
## $`D left`
##               [,1]      [,2]
## IGHD1-26 0.9671764 0.9632203
## IGHD2-15 0.9671133 0.9704196
## IGHD2-2  0.9704713 0.8401284
## IGHD2-21 0.9565619 0.9827526
## IGHD3-10 0.9348448 0.9723500
## IGHD3-16 1.0000000 0.9876989
## IGHD3-22 0.8958440 0.8363623
## IGHD3-9  0.8956084 0.9228335
## IGHD5-12 0.9056277 0.9541790
## IGHD6-13 0.9290143 0.9547091
## IGHD6-19 0.9096937 0.9703075
## 
## $`D right`
##               [,1]      [,2]
## IGHD1-26 0.9328609 0.9114610
## IGHD2-15 0.9488429 0.9448637
## IGHD2-2  0.9528677 0.9758707
## IGHD3-10 0.9729254 0.9929289
## IGHD3-16 0.9965636 0.9987699
## IGHD3-22 0.9271421 0.9484541
## IGHD3-9  0.9956803 0.9954068
## IGHD5-12 0.9290043 0.9748271
## IGHD6-13 0.6202728 0.7470627
## IGHD6-19 0.7597095 0.7841926
## 
## $J
##            [,1]      [,2]
## IGHJ1 0.9604520 0.9152901
## IGHJ3 0.6829488 0.8284958
## IGHJ4 0.8970930 0.8383887
## IGHJ5 0.9345740 0.9475216
## IGHJ6 0.9507971 0.9767419
pairs.plots(sam.dataset)

## NULL

## NULL

## NULL

## NULL
corr <- lapply(sam.dataset, cor)
corr
## $V
##            [,1]       [,2]
## [1,]  1.0000000 -0.6508373
## [2,] -0.6508373  1.0000000
## 
## $`D left`
##           [,1]      [,2]
## [1,] 1.0000000 0.2950375
## [2,] 0.2950375 1.0000000
## 
## $`D right`
##          [,1]     [,2]
## [1,] 1.000000 0.964784
## [2,] 0.964784 1.000000
## 
## $J
##          [,1]     [,2]
## [1,] 1.000000 0.732415
## [2,] 0.732415 1.000000
l_ply(corr, corrplot, method="number")

corr <- lapply(sam.dataset, cor, method = "spearman")
corr
## $V
##      [,1] [,2]
## [1,]  1.0 -0.5
## [2,] -0.5  1.0
## 
## $`D left`
##           [,1]      [,2]
## [1,] 1.0000000 0.5181818
## [2,] 0.5181818 1.0000000
## 
## $`D right`
##           [,1]      [,2]
## [1,] 1.0000000 0.9030303
## [2,] 0.9030303 1.0000000
## 
## $J
##      [,1] [,2]
## [1,]  1.0  0.7
## [2,]  0.7  1.0
l_ply(corr, corrplot, method="number")